package com.example.farmeri.ui.users;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.example.farmeri.R;
import com.example.farmeri.data.DataParam;
import com.example.farmeri.pojo.User;
import com.example.farmeri.ui.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 访问属性
 */
public class ViewPropertyActivity extends BaseActivity {
    private Dialog dialog;

    @BindView(R.id.check_property_userName)
    TextView textLoginName;

    @BindView(R.id.check_property_tel)
    TextView textTel;

    @BindView(R.id.check_property_email)
    TextView textEmail;

    @BindView(R.id.check_property_age)
    TextView textAge;

    @BindView(R.id.check_property_identify)
    TextView textIdentify;

    @BindView(R.id.check_property_place)
    TextView textPlace;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_property);
        ButterKnife.bind(this);
        initToolBar(R.id.check_property_toolbar,"访问属性",true,true);
        initData();
    }

    private void initData() {
        User user = DataParam.getUserInfo();
        textLoginName.setText(user.getLogin_name());
        textTel.setText(user.getTel());
        textEmail.setText(user.getEmail());
        textAge.setText(user.getAge());
        textIdentify.setText(user.getIdentity());
        textPlace.setText(user.getRequest_place());
    }

    //按钮 单击事件
    public void btnShowDialog_property(View view) {
        showDialog();// 单击按钮后 调用显示视图的 showDialog 方法，
    }

    /**
     * 显示弹出框
     */
    private void showDialog() {
        if (dialog == null) {
            initShareDialog();
        }
        dialog.show();
    }
    /**
     * 初始化分享弹出框
     */
    private void initShareDialog() {
        dialog = new Dialog(this, R.style.dialog_bottom_full);
        dialog.setCanceledOnTouchOutside(true); //手指触碰到外界取消
        dialog.setCancelable(true);             //可取消 为true

        Window window = dialog.getWindow();      // 得到dialog的窗体
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.share_animation);

        View view = View.inflate(this, R.layout.property_dialog_bottom, null); //获取布局视图
        view.findViewById(R.id.dialog_bottom_cancer).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        });
        window.setContentView(view);
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//设置横向全屏
    }
}
